package org.example.wx_springboot.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.wx_springboot.common.Result;
import org.example.wx_springboot.controller.request.CommodityPageRequest;
import org.example.wx_springboot.controller.request.DeliveryRequest;
import org.example.wx_springboot.entity.Commodity;
import org.example.wx_springboot.entity.Delivery;
import org.example.wx_springboot.entity.Shoppingcart;
import org.example.wx_springboot.service.IDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin//这个注解是解决跨域错误的
@RestController
@Slf4j
@RequestMapping("/delivery")
public class DeliveryConttroller {
    @Autowired
    IDeliveryService deliveryService;


    @GetMapping("/list")
    public Result list() {
        List<Delivery> delivery = deliveryService.list();
        return Result.success(delivery);//返回CommodityMapper的数据
    }

    //    后台添加列表
    @PostMapping("/seve")
    public Result save(@RequestBody Delivery delivery) {
        deliveryService.save(delivery);
        return Result.success();
    }

    //    修改
    @PutMapping("/update")
    public Result update(@RequestBody Delivery obj) {
        deliveryService.update(obj);
        return Result.success();
    }

    //    删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        deliveryService.deleteById(id);
        return Result.success();
    }
//    模糊查询
    @GetMapping("/page")
    //    将查询类放进来，放进来后去CommodityService将name和phone拿出来
    public Result page(DeliveryRequest DeliveryPageRequest) {
//        配置完去ICommodityService实践一下
        return Result.success(deliveryService.page(DeliveryPageRequest));
    }
}
